import json
import re
from playsound import playsound
from threading import Thread
from pynput import keyboard

with open("config.json", mode="r", encoding="utf-8") as f:
    config = f.read()
config = json.loads(config)


def on_press(key):
    key = str(key)
    key = re.sub(r'\'', '', key)
    print(key)
    if key == "Key.esc":
        return False
    if key in config:
        t = Thread(target=playsound, args=("./audio/"+config[key],))
        t.start()


if __name__ == "__main__":
    lsn = keyboard.Listener(on_press=on_press)
    lsn.start()
    lsn.join()
